﻿using System;
using System.Xml.Serialization;

namespace HamcoWcs.Models.TibcoMessage
{

    public abstract class BaseTibcoMessage
    {
        public BaseTibcoMessage()
        {
            RETURN = new MesMessageReturn("0", "");
        }

        public BaseTibcoMessage(string messageName, string inboxName = "", string listener = "") : this()
        {
            HEADER = new MesMessageHeader(messageName, inboxName, listener);
        }

        public MesMessageHeader HEADER { get; set; }
        public MesMessageReturn RETURN { get; set; }
    }

    public abstract class BaseTibcoMessage<T> : BaseTibcoMessage where T : class, new()
    {

        public BaseTibcoMessage() : base()
        {
        }

        public BaseTibcoMessage(string messageName, T body = null, string inboxName = "", string listener = "") : base(messageName, inboxName, listener)
        {
            Body = body;

        }

        [XmlElement("BODY")]
        public T Body { get; set; }
    }

    /// <summary>MES消息头</summary>
    public class MesMessageHeader
    {

        public MesMessageHeader()
        {

        }
        public MesMessageHeader(string messageName, string inboxName = "", string listener = "")
        {
            MESSAGENAME = messageName;
            TRANSACTIONID = DateTime.Now.ToString("yyyyMMddHHmmssffffff");
            REPLYSUBJECTNAME = TibcoConfiguration.BasicConfiguration.RecvSubject;
            INBOXNAME = inboxName;
            LISTENER = listener;
        }
        public string MESSAGENAME { get; set; }
        public string TRANSACTIONID { get; set; }
        public string REPLYSUBJECTNAME { get; set; }
        public string INBOXNAME { get; set; }
        public string LISTENER { get; set; }
    }

    /// <summary>MES消息return</summary>
    public class MesMessageReturn
    {
        public MesMessageReturn()
        {

        }
        public MesMessageReturn(string code, string Message)
        {
            RETURNCODE = code;
            this.RETURNMESSAGE = Message;
        }
        public string RETURNCODE { get; set; }
        public string RETURNMESSAGE { get; set; }
    }
}
